﻿using System;
using System.Configuration;
using Unknown.Framework.Database;
using Unknown.Framework.Injection;
using Unknown.Source.Business.Coder;

namespace Unknown.Source.Application.Builder
{
    /// <summary>
    /// 入口类
    /// </summary>
    public static class Entrance
    {
        private const string ConfigurationDirectoryKey = "ConfigurationDirectory";

        /// <summary>
        /// 配置目录
        /// </summary>
        public static string ConfigurationDirectory { get; set; }

        /// <summary>
        /// 入口
        /// </summary>
        [STAThread]
        public static void Main()
        {
            AutomateConfigurationHandler automateConfigurationHandler = new AutomateConfigurationHandler();
            automateConfigurationHandler.Example();
            ObjectConfigurationHandler objectConfigurationHandler = new ObjectConfigurationHandler();
            objectConfigurationHandler.Example();
            InstanceConfigurationHandler instanceConfigurationHandler = new InstanceConfigurationHandler();
            instanceConfigurationHandler.Example();
            CodeConfigurationHandler classCodeConfigurationHandler = new CodeConfigurationHandler();
            classCodeConfigurationHandler.Example();

            Entrance.ConfigurationDirectory = string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings[Entrance.ConfigurationDirectoryKey]);

            ObjectFactory.AutomateConfiguration(Entrance.ConfigurationDirectory, true);
            ObjectFactory.Configuration(Entrance.ConfigurationDirectory);

            DatabaseHandler.Configuration(Entrance.ConfigurationDirectory);

            classCodeConfigurationHandler.Build(Entrance.ConfigurationDirectory);

            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
            System.Windows.Forms.Application.Run(new Major());
        }
    }
}
